/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.palandrodev.calsmart.base;

/**
 * 
 * @author palaniappan
 */
public class CompoundInterest {

	private float principle;
	private float duration;
	private float interest;

	public float getPrinciple() {
		return principle;
	}

	public void setPrinciple(float principle) {
		this.principle = principle;
	}

	public float getDuration() {
		return duration;
	}

	public void setDuration(float duration) {
		this.duration = duration;
	}

	public float getInterest() {
		return interest;
	}

	public void setInterest(float interest) {
		this.interest = interest;
	}

	public CompoundInterest(float principle, float duration, float interest) {
		this.principle = principle;
		this.duration = duration;
		this.interest = interest;
	}

	public CompoundInterest() {
		this.principle = 0.0f;
		this.duration = 0.0f;
		this.interest = 0.0f;
	}

	public boolean isEmpty() {
		if (this.principle == 0.0f && this.duration == 0.0f
				&& this.interest == 0.0f) {
			return true;
		} else {
			return false;
		}
	}

	@Override
	public String toString() {
		if (this.isEmpty()) {
			return "";
		}
		return "CompoundInterest{" + "principle=" + principle + ", duration="
				+ duration + ", interest=" + interest + '}';
	}

	@Override
	public int hashCode() {
		if (this.isEmpty()) {
			return 0;
		} else {
			int hash = 7;
			hash = 83 * hash + Float.floatToIntBits(this.principle);
			hash = 83 * hash + Float.floatToIntBits(this.duration);
			hash = 83 * hash + Float.floatToIntBits(this.interest);
			return hash;
		}

	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		final CompoundInterest other = (CompoundInterest) obj;
		if (Float.floatToIntBits(this.principle) != Float
				.floatToIntBits(other.principle)) {
			return false;
		}
		if (Float.floatToIntBits(this.duration) != Float
				.floatToIntBits(other.duration)) {
			return false;
		}
		if (Float.floatToIntBits(this.interest) != Float
				.floatToIntBits(other.interest)) {
			return false;
		}
		return true;
	}

	public float calculate() {
		float amount;
		amount = (float) Math
				.pow(1 + (this.getInterest() / 100), this.duration);
		return this.principle * amount;
	}
}
